import { ConfigEnv, defineConfig,loadEnv } from 'vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
//引入svg需要用到插件
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { viteMockServe } from 'vite-plugin-mock'
import defineOptions from 'unplugin-vue-define-options/vite';


// https://vitejs.dev/config/
const viteConfig = defineConfig(({command,mode})=>{
const env = loadEnv(mode,process.cwd());
console.log(env);
return {
  plugins: [
    vue(),
    defineOptions(),
    viteMockServe({
      mockPath: 'mock',
      localEnabled: command === 'serve', // 开发环境开启mock
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
         symbolId: 'icon-[dir]-[name]',
    }),
  ],
  //vite配置
  define:{
  __APP_ENV__: JSON.stringify(env.APP_ENV), 
  },
  server:{
      port: 3000,
      open: true,
  },
  resolve:{
      alias:{
          '@': path.resolve('./src'),
      } 
  },
  //scss全局变量一个配置
  css: {
    preprocessorOptions: {
      scss: {
        javascriptEnabled: true,
        additionalData: `@import "./src/styles/variable.scss";`,
      },
    },
  },
}
  
})

export default viteConfig